package spring.com.redis.config;


/**
 * 缓存Key的拼接策略
 * @author RickSun
 * @version 2.0
 * @remark Powered by https://gitee.com/sunalee/fastboot
 * @remark fixed me
 */
public enum CacheMap {

    //系统级别缓存KEY
    TEN_GUARDIANS_KEY("PRODUCT:GUARDIAN_LIST","拼接自定义字符，存储十大金刚区list")
    ;

    private static final String proName = "LAGOLA:MALL:";
    private String keyName;
    private String keyRemark;

    private CacheMap(String keyName, String keyRemark){
        this.keyName =  proName + keyName ;
        this.keyRemark = keyRemark ;
    }

    public static String getKey(CacheMap cacheMap,Object ... param){
        StringBuffer sb = new StringBuffer(cacheMap.keyName);
        for (int i = 0; i < param.length; i++) {
            sb.append( ":"+param[i]);
        }
        return sb.toString();
    }

    public String getKeyName() {
        return keyName;
    }

    public String getKeyName(Object ... param) {
        StringBuffer sb = new StringBuffer(keyName);
        if( param == null ){
            return sb.toString();
        }
        for (int i = 0; i < param.length; i++) {
            sb.append( ":"+param[i]);
        }
        return sb.toString();
    }

    public  String getKeyName(Boolean isBatch,Object ... param){
        return getKeyName(param) + ":" +(isBatch ? "*" : "");
    }

}